

function showSearch() {
    var title = document.getElementById('searchtitle').value;
    if (title.replace(/\s+/g, "") == 0) {
        alert("请输入内容");
        return;
    }
    document.getElementById('showlink').innerHTML = "";
    var test;
    var m = 0;
    if (window.XMLHttpRequest) {
        test = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        test = new window.ActiveXObject();
    } else {
        alert("请升级至最新版本的浏览器");
    }
    if (test != null) {
        test.open("GET", "./searchdata/bloglink.json", true);
        test.send(null);
        test.onreadystatechange = function () {
            if (test.readyState == 4 && test.status == 200) {
                var obj = JSON.parse(test.responseText);
                for (var k in obj.bloglinks) {
                    //if(title==obj.bloglinks[k].title) {
                    if ((obj.bloglinks[k].title).indexOf(title) != -1) {
                        var newstr = obj.bloglinks[k].title.replace(title, ("<font style='color:red';>" + title + "</font>"));
                        document.getElementById('showlink').innerHTML += "<div class='title'><a href=./blogs/" + obj.bloglinks[k].link + ">" + newstr + "</a></div>";
                        m = 1;
                    }
                }
                if (!m) {
                    document.getElementById('showlink').innerHTML = "没有相关博客。";
                }

            }
        };

    }
} 
document.onkeydown = function (event) {//按回车搜索
    var e = event || window.event;
    if (e && e.keyCode == 13) { 
        showSearch(); 
    }
};